/*
********************************************************************************
* Copyright (C) 2021, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : app_view.cc
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2021-1-27 version v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
                Compile command: make
********************************************************************************
*/

#include <stdio.h>
#include "app_view.h"

#define VIEW_LOGI(fmt, args...) printf(fmt, ##args)
#define VIEW_LOGD(fmt, args...) //printf("%d AppView D: " fmt, __LINE__, ##args)
#define VIEW_LOGW(fmt, args...) printf("%d AppView W: " fmt, __LINE__, ##args)
#define VIEW_LOGE(fmt, args...) printf("%d AppView E: " fmt, __LINE__, ##args)
#define VIEW_LOG(fmt, args...)  printf(fmt, ##args)

// ------------------   ChromeView   ------------------
CChromeView::CChromeView(int XBegin, int XEnd, int YBegin, int YEnd)
{
    mXBegin = XBegin;
    mXEnd = XEnd;
    mYBegin = YBegin;
    mYEnd = YEnd;
    mNextHandler = NULL;
}

void CChromeView::SetNextHandler(CViewBase* handler)
{
    mNextHandler = handler;
}

void CChromeView::HandleRequest(void *request)
{
    if (!request) {
        VIEW_LOGE("request is invaild!\n");
    }

    if (IsSelect((SClickLocation *)request)) {
        VIEW_LOGI("Click Chrome!\n");
    } else {
        VIEW_LOGD("Next handler!\n");
        if (mNextHandler) {
            mNextHandler->HandleRequest(request);
        }
    }
}

bool CChromeView::IsSelect(SClickLocation *location)
{
    bool ret = false;

    if (   location->locX > mXBegin && location->locX < mXEnd
        && location->locY > mYBegin && location->locY < mYEnd
       )
    {
        ret = true;
    }

    return ret;
}

// ------------------   CTimView   ------------------
CTimView::CTimView(int XBegin, int XEnd, int YBegin, int YEnd)
{
    mXBegin = XBegin;
    mXEnd = XEnd;
    mYBegin = YBegin;
    mYEnd = YEnd;
    mNextHandler = NULL;
}

void CTimView::SetNextHandler(CViewBase* handler)
{
    mNextHandler = handler;
}

void CTimView::HandleRequest(void *request)
{
    if (!request) {
        VIEW_LOGE("request is invaild!\n");
    }

    if (IsSelect((SClickLocation *)request)) {
        VIEW_LOGI("Click Tim!\n");
    } else {
        VIEW_LOGD("Next handler!\n");
        if (mNextHandler) {
            mNextHandler->HandleRequest(request);
        }
    }
}

bool CTimView::IsSelect(SClickLocation *location)
{
    bool ret = false;

    if (   location->locX > mXBegin && location->locX < mXEnd
        && location->locY > mYBegin && location->locY < mYEnd
       )
    {
        ret = true;
    }

    return ret;
}
// ------------------   CWeChatView   ------------------
CWeChatView::CWeChatView(int XBegin, int XEnd, int YBegin, int YEnd)
{
    mXBegin = XBegin;
    mXEnd = XEnd;
    mYBegin = YBegin;
    mYEnd = YEnd;
    mNextHandler = NULL;
}

void CWeChatView::SetNextHandler(CViewBase* handler)
{
    mNextHandler = handler;
}

void CWeChatView::HandleRequest(void *request)
{
    if (!request) {
        VIEW_LOGE("request is invaild!\n");
    }

    if (IsSelect((SClickLocation *)request)) {
        VIEW_LOGI("Click WeChat!\n");
    } else {
        VIEW_LOGD("Next handler!\n");
        if (mNextHandler) {
            mNextHandler->HandleRequest(request);
        }
    }
}

bool CWeChatView::IsSelect(SClickLocation *location)
{
    bool ret = false;

    if (   location->locX > mXBegin && location->locX < mXEnd
        && location->locY > mYBegin && location->locY < mYEnd
       )
    {
        ret = true;
    }

    return ret;
}